import { _decorator, Component, Node } from "cc";
import { getGlobal } from "../Global";
const { ccclass, property } = _decorator;

@ccclass("createRoom")
export class createRoom extends Component {
  start() {}

  update(deltaTime: number) {}

  onOk() {
    this.node.active = false;
    this.createRoom();
  }
  createRoom() {
    let g = getGlobal();
    console.log(g.userMgr.statics, "?g.userMgr.statics");
    var data = {
      account: g.userMgr.statics.account,
      sign: g.userMgr.statics.sign,
      userid: g.userMgr.statics.userId,
      conf: JSON.stringify({
        difen: 1,
        zimo: 1,
        jiangdui: 1,
        huansanzhang: 1,
        zuidafanshu: 4,
        jushuxuanze: 1,
        dianganghua: 1,
        type: 1,
        menqing: 1,
        tiandihu: 1,
      }),
    };
    console.log(data, "?正在创建房间");
    g.wc.show("正在创建房间");
    function onCreate(ret) {
      if (ret.errcode !== 0) {
        g.wc.hide();
        //console.log(ret.errmsg);
        if (ret.errcode == 2222) {
          g.alert.show("提示", "钻石不足，创建房间失败!");
        } else {
          g.alert.show("提示", "创建房间失败,错误码:" + ret.errcode);
        }
      } else {
        g.gameNet.connectGameServer(ret);
      }
    }
    // g.http.setURL(g.SI.hall)
    g.http.sendRequest("/create_private_room", data, onCreate);
  }
}
